package cn.com.majiang.service.impl;

import cn.com.majiang.dao.RoomInfoDao;
import cn.com.majiang.domain.RoomInfo;
import cn.com.majiang.param.RoomInfoParam;
import cn.com.majiang.service.IRoomService;
import cn.com.majiang.util.RedisUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by jiangyanxin on 2017/5/14.
 */
@Service
public class RoomServiceImpl implements IRoomService{
    @Autowired
    private RoomInfoDao roomInfoDao;

    @Override
    public Map<String, Object> searchRoomList(RoomInfoParam param) {
        List<RoomInfo> list = new ArrayList<>();
        int count = roomInfoDao.selectRoomInfoCount(param);
        if(count > 0){
            if(param.getPage() != null) {
                param.setStartNum(param.getLimit() * (param.getPage() - 1));
            }
            List<RoomInfo> sellist = roomInfoDao.selectRoomInfoList(param);
            if(sellist != null && sellist.size() > 0){
                list = sellist;
            }
        }
        Map map = new HashMap();
        map.put("rows",list);
        map.put("count",count);
        map.put("onlineCount",0);
        if(StringUtils.isNotBlank(RedisUtil.getJedisValue("room.onlinenum"))){
            map.put("onlineCount", RedisUtil.getJedisValue("room.onlinenum"));
        }
        return map;
    }
}
